///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// It support directory's common operations on different os platform
///</describe>
/// <date>2021/1/31</date>
///***********************************************************************
#ifndef DIRECTORY_H
#define DIRECTORY_H

#include <time.h>
#include <iostream>
#include <string>
#include "boost/filesystem.hpp"

namespace SystemTool
{
	namespace IO
	{
		class Directory
		{
		public:
			typedef boost::filesystem::recursive_directory_iterator SearchIterator;

		public:
			// Create new directory recursively
			static bool Create(std::string strDirPath, bool bIsRecursive = true);

			// Copy the directory recursively
			static bool Copy(std::string strSrcDirPath, std::string strDestDirPath, bool bIsCover = false);

			// Delete the directory recursively
			static bool Delete(std::string strDirPath, bool bIsRecursive = false);

			// Transform window's path to unix path with "/"
			static bool TransformAsUnixPath(std::string strDirPath, std::string& strFinalDirPath);

			// Add path ending with "/"
			static std::string AddEnding(std::string strDirPath);

			// Trim path ending without "/"
			static std::string TrimEnding(std::string strDirPath);

			// Is the directory existed or not
			static bool IsExisted(std::string strDirPath);

			// Is directoy None or not
			static bool IsEmpty(std::string strDirPath);

			// Is directory
			static bool IsDirectory(std::string strDirPath);

			// Set current directory of project
			static bool SetCurDirectory(std::string strDirPath);

			// Get current directory of project
			static std::string GetCurDirectory();

			// Get exe's directory path with '/' ending
			static std::string GetExcutableDirectory();

			// Get last wite time of directory
			static std::time_t GetLastWriteTime(std::string strDirPath);

			// Set last wite time of directory
			static bool SetLastWriteTime(std::string strDirPath, std::time_t iNewTime);

			// Get the space of the entire disk which containing this directory
			static bool GetDiskSpace(std::string strDirPath,
				unsigned long long& CurDiskCapacity,				// Total space of the disk
				unsigned long long& CurDiskFreeSpace,			// Free space of the disk
				unsigned long long& CurDiskAvailableSpace); // Avalible space of the disk

			// Get rooth path of the directory
			static std::string GetRootPath(std::string strDirPath);

			// Get parent path of the directory
			static std::string GetParentPath(std::string strDirPath);

			// Get directory from the file path
			static std::string GetDirBy(std::string strFilePath);

			// Get search item (use it when you need SearchIterator to search your directory)
			static std::string GetSearchItem(SearchIterator& Iter);

			// Get all files under a directory
			static bool GetAllFiles(std::string strDir, std::vector<std::string>& vFileTable);
		};
	}
}

#endif // DIRECTORY_H
